package com.ruoyi.business.controller;

import com.ruoyi.business.domain.BusFygl;
import com.ruoyi.business.domain.vo.BusCbsfyVO;
import com.ruoyi.business.domain.vo.BusFyglSaveVO;
import com.ruoyi.business.service.IBusFyglService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 费用管理Controller
 *
 * @author yaowei
 * @date 2021-07-02
 */
@Api(description = "费用管理")
@RestController
@RequestMapping("/business/fygl")
public class BusFyglController extends BaseController {
    @Autowired
    private IBusFyglService busFyglService;

    /**
     * 承包商年度费用列表
     */
    @ApiOperation("承包商年度费用列表")
    @GetMapping("/cbsfyList")
    public TableDataInfo list(@RequestParam(required = false) String year) {
        startPage();
        List<BusCbsfyVO> list = busFyglService.cbsfyList(year);
        return getDataTable(list);
    }

    /**
     * 查询费用管理列表
     */
    @ApiOperation("根据ID查询工人信息")
    @GetMapping("/list")
    public TableDataInfo list(BusFygl busFygl) {
        startPage();
        List<BusFygl> list = busFyglService.selectBusFyglList(busFygl);
        return getDataTable(list);
    }

    /**
     * 导出费用管理列表
     */
    @PreAuthorize("@ss.hasPermi('business:fygl:export')")
    @Log(title = "费用管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(BusFygl busFygl) {
        List<BusFygl> list = busFyglService.selectBusFyglList(busFygl);
        ExcelUtil<BusFygl> util = new ExcelUtil<BusFygl>(BusFygl.class);
        return util.exportExcel(list, "fygl");
    }

    /**
     * 获取费用管理详细信息
     */
    @ApiOperation("根据ID查询工人信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(busFyglService.selectBusFyglById(id));
    }

    /**
     * 新增费用管理
     */
    @ApiOperation("费用新增/修改")
    @Log(title = "费用管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody List<BusFyglSaveVO> busFyglSaveList) {
        return toAjax(busFyglService.saveOrUpdate(busFyglSaveList));
    }

    /**
     * 修改费用管理
     */
    @PreAuthorize("@ss.hasPermi('business:fygl:edit')")
    @Log(title = "费用管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BusFyglSaveVO busFyglSaveVO) {
        return toAjax(busFyglService.updateBusFygl(busFyglSaveVO));
    }

    /**
     * 删除费用管理
     */
    @ApiOperation("根据ID删除费用信息")
    @Log(title = "费用管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(busFyglService.deleteBusFyglByIds(ids));
    }
}
